<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<link rel="stylesheet"  type="text/css"  href="bootstrap.css" >
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        html {
            height: 100%;
        }
        body {
            background:url(https://img.tukuppt.com/ad_preview/00/21/14/5f4378329e06b.jpg!/fw/980)no-repeat center center;
            height: 100%;
            width: 100%;
            background-size:cover;
            position:absolute;
            left:0;
            top:0
        }
    </style>
</head>
<body>
<div class="container">
    <div class="col-md-4"></div>
    <div class="col-md-4" style="background-color:#eee;;margin-top:200px;">
        <center>
            <h3>欢迎使用成绩管理系统</h3>
        </center>
        <form id="form-login" action="login" method="post">
            <div class="form-group">
                <label for="username">用户名:</label>
                <input type="text"  name="username" id="username" value="" class="form-control" style="color:red;">
            </div>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password"  name="password" id="password" value="" class="form-control" style="color:red;">
            </div>
            <div class="form-group">
                <label for="xingming">姓名</label>
                <input type="text"  name="xingming" id="xingming" value="" class="form-control" style="color:red;">
            </div>
            <div class="form-group">
                <label for="shenfen">身份</label>
                <select id="shenfen">
                    <option value="1">学生</option>
                    <option value="2">教师</option>
                </select>
            </div>
            <div class="form-group">
                <input type="button" onclick="f2()" value="返回" class="btn btn-primary">
                <input type="button" onclick="f1()" value="注册" class="btn btn-primary">
            </div>

        </form>
    </div>
    <div class="col-md-4"></div>
</div>
</body>
</html>
<script>
    function f2(){
        window.location.href="login.html";
    }
    function f1(){
        var username = $("#username").val();
        var password = $("#password").val();
        var xingming = $("#xingming").val();
        var shenfen = $("#shenfen").val();
        if(username==""||password==""||xingming==""||shenfen==""){
            alert("请输入完整信息");
            return;
        }
        $.ajax({
            "url":"/user/register",
            "data": {
                'username':username,
                'password':password,
                'xingming':xingming,
                'shenfen':shenfen
            },
            "type":"post",
            "dataType":"json",
            "success":function(json) {
                console.log(json)
                if(json.state == '1'){
                    alert('注册成功');
                    window.location.href="login.html";
                }else{
                    alert(json.message);
                }
            }
        });
    }
</script>